package cn.lysj.framework.store.controller;

import cn.lysj.framework.base.BaseController;
import cn.lysj.framework.common.annotation.CurrentUser;
import cn.lysj.framework.common.domain.User;
import cn.lysj.framework.common.utils.pagination.PageVo;
import cn.lysj.framework.common.utils.web.Resp;

import cn.lysj.framework.store.domain.UserFeedback;
import cn.lysj.framework.store.service.UserFeedbackService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author drj
 * @description 用户反馈消息控制层
 * @create 2018-10-29 09:55:48
 **/
@Slf4j
@RestController
@Api(description = "用户反馈消息管理接口")
@RequestMapping("/user_feedback")
public class UserFeedbackController extends BaseController<UserFeedback> {

    @Resource
    private UserFeedbackService userFeedbackService;

    @Override
    public UserFeedbackService getService() {
        return userFeedbackService;
    }

    @Override
    public Resp list(UserFeedback userFeedback, PageVo pageVo){
        return null;
    }

    //品类列表
    @PostMapping("/read")
    public Resp read(String id) {
        UserFeedback userFeedback = userFeedbackService.getRepository().findOne(id);
        if (null == userFeedback) {
            return new Resp(Resp.PARAM_ERROR, "未知错误");
        }
        userFeedback.setReadFlag(2);
        userFeedback.setUpdateTime(new Date());
        userFeedbackService.getRepository().save(userFeedback);
        return new Resp("查看成功");
    }

    @GetMapping("/list_rewrite")
    public Resp list(@CurrentUser User user, UserFeedback userFeedback, PageVo pageVo){
        userFeedback.setStoreId(user.getStoreId());
        return new Resp(userFeedbackService.list(userFeedback,pageVo));
    }

}
